﻿<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <link rel="stylesheet" href="../styles/table-transparent.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../Scripts/datav.min.vue.js"></script>
  <script src="../Scripts/lodash.min.js"></script>
  <script src="../Scripts/gsap.min.js"></script>
  <title>齐套性检查看板</title>
  <style>
    html {
      background-image: url(../images/bg.jpg);
      color: #fff;
    }

    .header-title {
      font-size: 24px !important;
    }

    .el-form-item__label {
      color: #fff;
    }

    .el-form-item {
      margin-bottom: 0px;
    }

    .chart-title {
      text-align: center;
      padding-top: 10px;
      color: #fff;
    }

    .chart {
      width: 100%;
      height: 80px;
      font-size: 40px;
      font-weight: bold;
      cursor: pointer;
      text-align: center;
    }

    .green {
      color: #0fd850;
    }

    .yellow {
      color: #fffc00;
    }

    .red {
      color: #ff0844;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak>
    <div style="padding:0 10px;">
      <div class="parallelogram header-outer">
        <el-row>
          <el-col :span="7" style="padding-left: 35px;">
            <img src="../images/aeec_logo.png" height="60" alt="黎阳LOGO" />
          </el-col>
          <el-col :span="10" class="header-title">
            <div class="parallelogram header-inner">
              {{queryInfo.factoryname}}齐套性检查看板
            </div>
          </el-col>
          <el-col :span="7" class="currentTime" style="padding-right: 35px;font-size: 18px;">
            {{currentTime}}
          </el-col>
        </el-row>
      </div>

      <!-- 查询区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'" :rules="rules"
        style="margin:10px 10px 0 10px;">
        <el-form-item label="组织结构:" prop="selectOrg">
          <el-cascader :options="orginazition" :props="{ checkStrictly: true}" ref="orginazitionRef"
            v-model="queryInfo.selectOrg" clearable style="width:340px;">
          </el-cascader>
        </el-form-item>

        <el-form-item label="要求完成时间:" prop="selectdate">
          <el-date-picker v-model="queryInfo.selectdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="handleSearchBtnClick">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="getExportExcel">导出</el-button>
          <el-link type="primary" icon="el-icon-link" icon="el-icon-edit" @click="handleLinkClick"
            style="margin-left: 10px;">
            齐套性检查趋势看板
          </el-link>
        </el-form-item>
      </el-form>

      <el-row :gutter="10">
        <el-col :span="4">
          <dv-border-box-10>
            <h3 class="chart-title">工艺路线齐套率</h3>
            <div ref="workflowrate" class="chart" :class="chartClassNameConfig.workflowrateClassName"
              @click="getDetail('workflowrate',1)">
              {{chartData.workflowrate}}%
            </div>
          </dv-border-box-10>
        </el-col>
        <el-col :span="4">
          <dv-border-box-10>
            <h3 class="chart-title">排产数据齐套率</h3>
            <div ref="apsrate" class="chart" :class="chartClassNameConfig.apsrateClassName"
              @click="getDetail('apsrate',1)">
              {{chartData.apsrate}}%
            </div>
          </dv-border-box-10>
        </el-col>
        <el-col :span="4">
          <dv-border-box-10>
            <h3 class="chart-title">工装工具齐套率</h3>
            <div ref="toolrate" class="chart" :class="chartClassNameConfig.toolrateClassName"
              @click="getDetail('toolrate',1)">
              {{chartData.toolrate}}%
            </div>
          </dv-border-box-10>
        </el-col>
        <el-col :span="4">
          <dv-border-box-10>
            <h3 class="chart-title">生产物资齐套率</h3>
            <div ref="materialrate" class="chart" :class="chartClassNameConfig.materialrateClassName"
              @click="getDetail('materialrate',1)">
              {{chartData.materialrate}}%
            </div>
          </dv-border-box-10>
        </el-col>
        <el-col :span="4">
          <dv-border-box-10>
            <h3 class="chart-title">设备状态齐套率</h3>
            <div ref="resourcesrate" class="chart" :class="chartClassNameConfig.resourcesrateClassName"
              @click="getDetail('resourcesrate',1)">
              {{chartData.resourcesrate}}%
            </div>
          </dv-border-box-10>
        </el-col>
        <el-col :span="4">
          <dv-border-box-10>
            <h3 class="chart-title">特殊过程齐套率</h3>
            <div ref="spotcheckrate" class="chart" :class="chartClassNameConfig.spotcheckrateClassName"
              @click="getDetail('spotcheckrate',1)">
              {{chartData.spotcheckrate}}%
            </div>
          </dv-border-box-10>
        </el-col>
      </el-row>

      <!-- 表格 -->
      <dv-border-box-10>
        <h3 class="chart-title">生产准备缺项明细</h3>
        <div id="datagrid" style="padding:10px;" class="custom-scrollable-element">
          <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
            element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border :height="tableHeight">
            <el-table-column type="index" width="50"></el-table-column>
            <el-table-column label="主制厂" prop="fromfactoryname" width="100"></el-table-column>
            <el-table-column label="批次号" prop="containername"></el-table-column>
            <el-table-column label="工序" prop="workflowstepname" width="160" show-overflow-tooltip></el-table-column>
            <el-table-column label="工艺路线" prop="workflowname" width="260" show-overflow-tooltip></el-table-column>
            <el-table-column label="工艺路线版本" prop="workflowrevision" width="130" show-overflow-tooltip></el-table-column>
            <el-table-column label="转工计划开始时间" prop="starttime" width="160">
              <template slot-scope="scope">
                <span v-if="scope.row.starttime">{{scope.row.starttime.replace('T',' ')}}</span>
              </template>
            </el-table-column>
            <el-table-column label="工艺路线齐套" prop="iscompworkflow" width="120">
              <template slot-scope="scope">
                <el-tag effect="dark" :type="scope.row.iscompworkflow === 1 ? 'success' : 'danger'">
                  {{scope.row.iscompworkflow === 1 ? '是' : '否'}}
                </el-tag>
              </template>
            </el-table-column>
            <el-table-column label="排产数据齐套" prop="iscompaps" width="120">
              <template slot-scope="scope">
                <el-tag effect="dark" :type="scope.row.iscompaps === 1 ? 'success' : 'danger'">
                  {{scope.row.iscompaps === 1 ? '是' : '否'}}
                </el-tag>
              </template>
            </el-table-column>
            <el-table-column label="工装工具齐套" prop="iscomptool" width="120">
              <template slot-scope="scope">
                <el-tag effect="dark" :type="scope.row.iscomptool === 1 ? 'success' : 'danger'">
                  {{scope.row.iscomptool === 1 ? '是' : '否'}}
                </el-tag>
              </template>
            </el-table-column>
            <el-table-column label="生产物资齐套" prop="iscompmaterial" width="120">
              <template slot-scope="scope">
                <el-tag effect="dark" :type="scope.row.iscompmaterial === 1 ? 'success' : 'danger'">
                  {{scope.row.iscompmaterial === 1 ? '是' : '否'}}
                </el-tag>
              </template>
            </el-table-column>
            <el-table-column label="设备状态齐套" prop="iscompresource" width="120">
              <template slot-scope="scope">
                <el-tag effect="dark" :type="scope.row.iscompresource === 1 ? 'success' : 'danger'">
                  {{scope.row.iscompresource === 1 ? '是' : '否'}}
                </el-tag>
              </template>
            </el-table-column>
            <el-table-column label="特殊过程齐套" prop="iscompspotcheck" width="120">
              <template slot-scope="scope">
                <el-tag effect="dark" :type="scope.row.iscompspotcheck === 1 ? 'success' : 'danger'">
                  {{scope.row.iscompspotcheck === 1 ? '是' : '否'}}
                </el-tag>
              </template>
            </el-table-column>
          </el-table>
          <el-pagination :current-page="queryInfo.currentPage" :page-sizes="[queryInfo.pageSize,20,50,100]"
            :page-size="queryInfo.pageSize" layout="prev,pager,next,jumper,sizes,total" :total="total"
            @size-change="handleSizeChange" @current-change="handleCurrentChange">
          </el-pagination>
        </div>
      </dv-border-box-10>

      <!-- 明细对话框 -->
      <el-dialog :title="chartDetail.title" :width="'98%'" :top="'10px'" :center="'center'"
        :visible.sync="chartDetail.dialogVisiable">
        <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
          element-loading-background="rgba(0,0,0,0.8)" :data="chartDetail.dataList" stripe border>
          <el-table-column type="index" width="50"></el-table-column>
          <el-table-column label="主制厂" prop="fromfactoryname" width="100"></el-table-column>
          <el-table-column label="批次号" prop="containername"></el-table-column>
          <el-table-column label="工序" prop="workflowstepname"></el-table-column>
          <el-table-column label="工艺路线" prop="workflowname"></el-table-column>
          <el-table-column label="工艺路线版本" prop="workflowrevision"></el-table-column>
          <el-table-column label="转工计划开始时间" prop="starttime" width="160">
            <template slot-scope="scope">
              <span v-if="scope.row.starttime">{{scope.row.starttime.replace('T',' ')}}</span>
            </template>
          </el-table-column>
          <el-table-column label="工艺路线齐套" prop="iscompworkflow" width="120" v-if="displayConfig.workflowrate">
            <template slot-scope="scope">
              <el-tag effect="dark" :type="scope.row.iscompworkflow === 1 ? 'success' : 'danger'">
                {{scope.row.iscompworkflow === 1 ? '是' : '否'}}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="排产数据齐套" prop="iscompaps" width="120" v-if="displayConfig.apsrate">
            <template slot-scope="scope">
              <el-tag effect="dark" :type="scope.row.iscompaps === 1 ? 'success' : 'danger'">
                {{scope.row.iscompaps === 1 ? '是' : '否'}}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="工装工具齐套" prop="iscomptool" width="120" v-if="displayConfig.toolrate">
            <template slot-scope="scope">
              <el-tag effect="dark" :type="scope.row.iscomptool === 1 ? 'success' : 'danger'">
                {{scope.row.iscomptool === 1 ? '是' : '否'}}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="生产物资齐套" prop="iscompmaterial" width="120" v-if="displayConfig.materialrate">
            <template slot-scope="scope">
              <el-tag effect="dark" :type="scope.row.iscompmaterial === 1 ? 'success' : 'danger'">
                {{scope.row.iscompmaterial === 1 ? '是' : '否'}}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="设备状态齐套" prop="iscompresource" width="120" v-if="displayConfig.resourcesrate">
            <template slot-scope="scope">
              <el-tag effect="dark" :type="scope.row.iscompresource === 1 ? 'success' : 'danger'">
                {{scope.row.iscompresource === 1 ? '是' : '否'}}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="特殊过程齐套" prop="iscompspotcheck" width="120" v-if="displayConfig.spotcheckrate">
            <template slot-scope="scope">
              <el-tag effect="dark" :type="scope.row.iscompspotcheck === 1 ? 'success' : 'danger'">
                {{scope.row.iscompspotcheck === 1 ? '是' : '否'}}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="责任者" prop="iscompspotcheck" width="120">
            <template slot-scope="scope">
              <span v-if="chartDetail.queryInfo.seriesName === 'workflowrate'">工艺组</span>
              <span v-else-if="chartDetail.queryInfo.seriesName === 'apsrate'">计划组</span>
              <span v-else-if="chartDetail.queryInfo.seriesName === 'toolrate'">物料组</span>
              <span v-else-if="chartDetail.queryInfo.seriesName === 'materialrate'">物料组</span>
              <span v-else-if="chartDetail.queryInfo.seriesName === 'resourcesrate'">设备组</span>
              <span v-else>工艺组</span>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination @current-change="handleDetailCurrentChange" :current-page="chartDetail.queryInfo.currentPage"
          :page-sizes="[chartDetail.queryInfo.pageSize]" :page-size="chartDetail.queryInfo.pageSize"
          layout="prev,pager,next,jumper,sizes,total" :total="chartDetail.total">
        </el-pagination>
      </el-dialog>
    </div>
  </div>
  <script src=" ../Scripts/echarts/echarts-5.4.0.min.js">
  </script>
  <script type="module">
    import { getParams, exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { pieOption } from '../Scripts/hooks/pieChartConfig.js'
    import { getMESOrginazition, getFactoryInfo } from '../Scripts/hooks/fetchAPI.js'
    const app = new Vue({
      el: '#app',
      data: {
        total: 0,
        loading: false,
        loadingText: '数据加载中...',
        currentTime: '',
        orginazition: [],
        queryInfo: {
          selectdate: '',
          factoryname: '',
          selectOrg: '',
          currentPage: 1,//当前页
          pageSize: 12//每页显示条数
        },
        dataList: [],
        rules: {
          selectOrg: [{ required: true, message: '组织结构不能为空', trigger: 'change' }],
          selectdate: [{ required: true, message: '要求完成时间不能为空', trigger: 'change' }]
        },
        loadingConfig: { text: '数据查询中...', effect: 'whirling', maskColor: 'transparent', textColor: '#000', color: '#66b1ff' },
        tableHeight: window.innerHeight - 400,
        chartData: {
          apsrate: 0,
          materialrate: 0,
          resourcesrate: 0,
          spotcheckrate: 0,
          toolrate: 0,
          workflowrate: 0
        },
        // 颜色配置
        chartClassNameConfig: {
          apsrateClassName: '',
          materialrateClassName: '',
          resourcesrateClassName: '',
          spotcheckrateClassName: '',
          toolrateClassName: '',
          workflowrateClassName: ''
        },
        chartDetail: {
          dialogVisiable: false,
          queryInfo: { seriesName: '', currentPage: 1, pageSize: 12 },
          dataList: [], title: '', total: 0
        },
        mapping: [
          { label: '工艺路线齐套率', field: 'workflowrate' },
          { label: '排产数据齐套率', field: 'apsrate' },
          { label: '工装工具齐套率', field: 'toolrate' },
          { label: '生产物资齐套率', field: 'materialrate' },
          { label: '设备状态齐套率', field: 'resourcesrate' },
          { label: '特殊过程齐套率', field: 'spotcheckrate' },
        ],
        displayConfig: {
          workflowrate: true,
          apsrate: true,
          toolrate: true,
          materialrate: true,
          resourcesrate: true,
          spotcheckrate: true
        }
      },
      methods: {
        setClassName(key, value) {
          if (value === null) { return this.chartClassNameConfig[key + 'ClassName'] = ''; }

          if (value >= 95) {
            this.chartClassNameConfig[key + 'ClassName'] = 'green';
          } else if (value >= 80) {
            this.chartClassNameConfig[key + 'ClassName'] = 'yellow';
          } else {
            this.chartClassNameConfig[key + 'ClassName'] = 'red';
          }
        },
        // 查询统计数据
        async getChartData() {
          this.loading = true;
          this.loadingText = '数据查询中...';
          const { data: { data, meta, total } } = await axios({
            method: 'post',
            url: '../handler/board/RbCompleteSetRateDashBoard.ashx?action=getChartData',
            data: { type: 'getChartData', ...this.queryInfo }
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.chartData = data[0];

          const refsArr = ['workflowrate', 'apsrate', 'toolrate', 'materialrate', 'resourcesrate', 'spotcheckrate'];

          for (const i of refsArr) {
            gsap.fromTo(
              this.$refs[i],
              { textContent: 0 },// 初始状态，数字初始为0
              { textContent: (this.chartData[i] ? this.chartData[i] : 0) + '%', duration: 0.5 }
            );
          }

          for (const key in this.chartData) {
            this.setClassName(key, this.chartData[key]);
          }
        },
        // 查询表格数据
        async getData() {
          this.loading = true;
          this.loadingText = '数据查询中...';
          const { data: { data, meta, total } } = await axios({
            method: 'post',
            url: '../handler/board/RbCompleteSetRateDashBoard.ashx?action=getData',
            data: { type: 'getData', ...this.queryInfo, status: '未齐套' }
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.dataList = data;
          this.total = total;
        },
        // 查询明细
        async getDetail(name, currentPage) {
          const value = this.chartData[name];
          const label = this.mapping.filter(i => i.field === name)[0].label;
          if (value === null) { return this.$message.error(`【${label}】没有数据，不能查看明细`); }
          if (value === 100) { return this.$message.warning(`【${label}】已齐套，不能查看明细`); }

          this.chartDetail.title = `【${label}】未齐套明细数据`;
          this.chartDetail.dialogVisiable = true;

          for (const key in this.displayConfig) {
            if (key === name) {
              this.displayConfig[key] = true;
            } else {
              this.displayConfig[key] = false;
            }
          }

          this.loading = true;
          this.loadingText = '数据查询中...';

          this.chartDetail.queryInfo.seriesName = name;
          this.chartDetail.queryInfo.currentPage = currentPage;

          const { data: { data, meta, total } } = await axios({
            method: 'post',
            url: '../handler/board/RbCompleteSetRateDashBoard.ashx?action=getDetail',
            data: { type: 'getDetail', ...this.queryInfo, seriesName: name, ...this.chartDetail.queryInfo }
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.chartDetail.dataList = data;
          this.chartDetail.total = total;
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        },
        // 对话框分页事件
        handleDetailCurrentChange(newPage) {
          this.getDetail(this.chartDetail.queryInfo.seriesName, newPage);
        },
        handleSearchBtnClick() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (valid) {
              this.getData();
              this.getChartData();
            }
          });
        },
        // 导出excel
        async getExportExcel() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (valid) {
              const config = {
                url: '../handler/board/RbCompleteSetRateDashBoard.ashx?action=exportExcel',
                data: { type: 'exportExcel', ...this.queryInfo, status: '未齐套' }
              }
              exportExcelData(config, this);
            }
          })
        },
        handleLinkClick() {
          let { href } = window.location;
          href = href.replace('RBCompleteSetRateDashBoard', 'RBCompleteSetRateChartDashBoard');
          window.open(href);
        }
      },
      async mounted() {
        let incrementNumber = () => {
          setTimeout(incrementNumber, 1000);
          const weekDayText = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'][dayjs().format('d')];
          this.currentTime = `${dayjs().format('YYYY年MM月DD日')} ${weekDayText} ${dayjs().format('HH:mm')}`;
        }
        setTimeout(incrementNumber, 500);
        const startdate = dayjs().format('YYYY-MM-DD');
        const enddate = dayjs().add(3, 'day').format('YYYY-MM-DD');
        this.queryInfo.selectdate = [startdate, enddate];

        const factoryInfo = await getFactoryInfo({ factoryid: Decrypt(getParams('factoryid')), isMapping: '是' });
        const { factoryname } = factoryInfo[0];
        this.queryInfo.factoryname = factoryname;
        this.orginazition = await getMESOrginazition({ isMapping: '是', factoryCode: '602' });
        this.queryInfo.selectOrg = [this.orginazition[0].value];
        this.getData();
        this.getChartData();
        window.addEventListener('resize', () => {
          this.tableHeight = window.innerHeight - 400
        });
      }
    })
  </script>
</body>

</html>